COVID-19 statistics and trend

In [1]:
import pandas as pd
import os
import plotly.graph_objects as go
import plotly.io as pio
import plotly.offline as py
from scipy.optimize import curve_fit
from datetime import datetime
import re
In [2]:
pd.set_option("display.max_rows", 250)
In [3]:
pio.renderers.default = 'notebook'
In [4]:
from datetime import datetime

now = datetime.now()

current_time = now.strftime("%d-%m-%Y %H:%M")
print("Updated on", current_time, "h")
Updated on 10-07-2020 12:00 h
In [5]:
################################ Loading xls
In [6]:
url = "https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide.xlsx"
In [7]:
cases = pd.read_excel(url)
In [8]:
#filepath = "C:\\Users\\edidd\\Documents\\Ubiqum\\Data Analytics Course\\covid19\\data\\"
In [9]:
#cases = pd.read_excel(os.path.join(filepath, "COVID-19-geographic-disbtribution-worldwide-2020-04-23.xlsx"))
In [10]:
# filepath2 = "C:\\Users\\edidd\\Documents\\covid19_JHU_CSSE\\COVID-19\\"
In [11]:
# data_jhu= pd.read_csv(os.path.join(filepath2, "who_covid_19_situation_reports\\who_covid_19_sit_rep_time_series\\who_covid_19_sit_rep_time_series.csv"))
In [12]:
############################# Data wrangling
In [13]:
cases.dateRep = pd.to_datetime(cases.dateRep, format="%Y-%m-%d")
In [14]:
cases = cases.rename(columns= {
    "dateRep": "date", 
    "countriesAndTerritories": "country", 
    "cases": "newcases", 
    "deaths": "newdeaths"})
In [15]:
cases = cases.sort_values(by=["country", "date"])
In [16]:
cases["cumcases"]= cases.groupby("country")["newcases"].cumsum()
In [17]:
######################### Deleting rows with 0 cumulative cases
In [18]:
cases= cases.loc[cases.cumcases != 0,:]
In [19]:
cases= cases.set_index("country")

Summary

In [20]:
# Grouping by country
In [21]:
cases_total= cases.groupby(["country"]).sum().sort_values(by= ["newcases"], ascending= False)
In [22]:
cases_total= cases_total.rename(columns= {"newcases": "total_cases", "newdeaths": "total_deaths"})
In [23]:
cases_total= cases_total.drop(["day", "month", "year", "popData2019", "cumcases"], axis= "columns")
In [24]:
cases_total["death_ratio"]= cases_total.total_deaths / cases_total.total_cases * 100
In [25]:
cases_total["population_2019"]= cases.groupby("country").max().popData2019
In [26]:
cases_total["cases_to_population"]= cases_total.total_cases / cases_total.population_2019 * 100
In [27]:
cases_total["cases_to_population"]= cases_total["cases_to_population"].map('{:,.2f}%'.format)
In [28]:
cases_total["death_ratio"]= cases_total["death_ratio"].map('{:,.2f}%'.format)

Global total of confirmed cases

12017118

Totals per country

In [30]:
fig = go.Figure(data= [go.Bar(x= cases_total.index, 
                              y= cases_total.total_cases.head(10), 
                              text= "*" + cases_total.cases_to_population, 
                              textposition='auto')
                      ]
               )
fig.update_layout(title= "Total confirmed cases per country - top 10", 
                  xaxis_title= "* Showing percentage of country's population")
fig.show()
In [31]:
morethan1000 = cases_total.loc[cases_total.total_cases >= 1000, :].copy()
In [32]:
morethan1000["death_ratio"] = morethan1000.total_deaths / morethan1000.total_cases
In [33]:
fig= go.Figure()

fig.add_trace(go.Histogram(x= morethan1000.death_ratio, 
                           histnorm= "probability",
                           xbins=dict(
                               start=0,
                               end=morethan1000.death_ratio.max(),
                               size=.01
                           )
                          )
             )

fig.update_layout(title= "Global distribution of death ratio", 
                 xaxis=dict(tickformat= "%", tickangle=0, 
                            title='* Only countries with more than 999 reported cases are considered'))

pio.show(fig)

Complete list

total_cases total_deaths death_ratio population_2019 cases_to_population
country
United_States_of_America 3055004 132309 4.33% 3.290649e+08 0.93%
Brazil 1713160 67964 3.97% 2.110495e+08 0.81%
India 767296 21129 2.75% 1.366418e+09 0.06%
Russia 700792 10667 1.52% 1.458723e+08 0.48%
Peru 312911 11133 3.56% 3.251046e+07 0.96%
Chile 303083 6573 2.17% 1.895204e+07 1.60%
United_Kingdom 286979 44517 15.51% 6.664711e+07 0.43%
Mexico 275003 32796 11.93% 1.275755e+08 0.22%
Spain 252513 28396 11.25% 4.693706e+07 0.54%
Iran 248379 12084 4.87% 8.291389e+07 0.30%
Italy 242149 34914 14.42% 6.035955e+07 0.40%
Pakistan 240848 4983 2.07% 2.165653e+08 0.11%
South_Africa 224665 3602 1.60% 5.855827e+07 0.38%
Saudi_Arabia 220144 2059 0.94% 3.426853e+07 0.64%
Turkey 208938 5282 2.53% 8.200388e+07 0.25%
Germany 197783 9048 4.57% 8.301921e+07 0.24%
Bangladesh 172134 2197 1.28% 1.630462e+08 0.11%
France 169473 29965 17.68% 6.701288e+07 0.25%
Colombia 128638 4527 3.52% 5.033944e+07 0.26%
Canada 106422 8737 8.21% 3.741104e+07 0.28%
Qatar 101553 138 0.14% 2.832071e+06 3.59%
China 84950 4641 5.46% 1.433784e+09 0.01%
Argentina 83413 1654 1.98% 4.478068e+07 0.19%
Egypt 78304 3564 4.55% 1.003881e+08 0.08%
Sweden 73858 5482 7.42% 1.023018e+07 0.72%
Indonesia 68079 3359 4.93% 2.706256e+08 0.03%
Iraq 67442 2779 4.12% 3.930979e+07 0.17%
Belarus 64224 443 0.69% 9.452409e+06 0.68%
Ecuador 64221 4900 7.63% 1.737366e+07 0.37%
Belgium 62210 9778 15.72% 1.145552e+07 0.54%
United_Arab_Emirates 53045 327 0.62% 9.770526e+06 0.54%
Kazakhstan 53021 264 0.50% 1.855143e+07 0.29%
Kuwait 52007 379 0.73% 4.207077e+06 1.24%
Ukraine 51224 1327 2.59% 4.399364e+07 0.12%
Netherlands 50691 6126 12.08% 1.728216e+07 0.29%
Philippines 50359 1314 2.61% 1.081166e+08 0.05%
Oman 50207 233 0.46% 4.974992e+06 1.01%
Singapore 45298 26 0.06% 5.804343e+06 0.78%
Portugal 44859 1631 3.64% 1.027662e+07 0.44%
Bolivia 42984 1577 3.67% 1.151310e+07 0.37%
Panama 41251 819 1.99% 4.246440e+06 0.97%
Dominican_Republic 39588 829 2.09% 1.073896e+07 0.37%
Poland 36689 1542 4.20% 3.797281e+07 0.10%
Afghanistan 33653 937 2.78% 3.804176e+07 0.09%
Israel 33557 344 1.03% 8.519373e+06 0.39%
Switzerland 32413 1685 5.20% 8.544527e+06 0.38%
Bahrain 30931 100 0.32% 1.641164e+06 1.88%
Nigeria 30249 684 2.26% 2.009636e+08 0.02%
Romania 30175 1817 6.02% 1.941446e+07 0.16%
Armenia 29820 521 1.75% 2.957728e+06 1.01%
Honduras 25978 694 2.67% 9.746115e+06 0.27%
Ireland 25542 1743 6.82% 4.904240e+06 0.52%
Guatemala 25411 1053 4.14% 1.758148e+07 0.14%
Ghana 22822 129 0.57% 3.041786e+07 0.08%
Azerbaijan 21916 274 1.25% 1.004772e+07 0.22%
Japan 20174 980 4.86% 1.268603e+08 0.02%
Austria 18516 706 3.81% 8.858775e+06 0.21%
Moldova 18471 614 3.32% 4.043258e+06 0.46%
Algeria 17348 978 5.64% 4.305305e+07 0.04%
Serbia 17076 341 2.00% 6.963764e+06 0.25%
Nepal 16423 35 0.21% 2.860872e+07 0.06%
Cameroon 14916 359 2.41% 2.587639e+07 0.06%
Morocco 14771 242 1.64% 3.647177e+07 0.04%
South_Korea 13293 287 2.16% 5.122532e+07 0.03%
Denmark 12900 609 4.72% 5.806081e+06 0.22%
Czechia 12814 351 2.74% 1.064980e+07 0.12%
Cote_dIvoire 11504 78 0.68% 2.571655e+07 0.04%
Uzbekistan 11259 47 0.42% 3.298172e+07 0.03%
Sudan 10084 636 6.31% 4.281324e+07 0.02%
Norway 8947 251 2.81% 5.328212e+06 0.17%
Puerto_Rico 8904 159 1.79% 2.933404e+06 0.30%
Australia 8886 106 1.19% 2.520320e+07 0.04%
Kyrgyzstan 8847 116 1.31% 6.415851e+06 0.14%
Malaysia 8677 121 1.39% 3.194979e+07 0.03%
El_Salvador 8566 235 2.74% 6.453550e+06 0.13%
Kenya 8528 169 1.98% 5.257397e+07 0.02%
Venezuela 8010 75 0.94% 2.851583e+07 0.03%
Democratic_Republic_of_the_Congo 7737 184 2.38% 8.679057e+07 0.01%
Senegal 7657 141 1.84% 1.629636e+07 0.05%
North_Macedonia 7401 359 4.85% 2.077132e+06 0.36%
Finland 7265 329 4.53% 5.517919e+06 0.13%
Ethiopia 6774 120 1.77% 1.120787e+08 0.01%
Haiti 6486 123 1.90% 1.126308e+07 0.06%
Tajikistan 6364 54 0.85% 9.321023e+06 0.07%
Bulgaria 6342 259 4.08% 7.000039e+06 0.09%
Gabon 5871 46 0.78% 2.172578e+06 0.27%
Bosnia_and_Herzegovina 5869 209 3.56% 3.300998e+06 0.18%
Costa_Rica 5836 24 0.41% 5.047561e+06 0.12%
Guinea 5697 34 0.60% 1.277125e+07 0.04%
Palestine 5567 25 0.45% 4.981422e+06 0.11%
Mauritania 5024 135 2.69% 4.525698e+06 0.11%
Djibouti 4889 55 1.12% 9.735570e+05 0.50%
Luxembourg 4650 110 2.37% 6.138940e+05 0.76%
Hungary 4210 589 13.99% 9.772756e+06 0.04%
Central_African_Republic 4109 52 1.27% 4.745179e+06 0.09%
Kosovo 3886 82 2.11% 1.798506e+06 0.22%
Greece 3622 193 5.33% 1.072460e+07 0.03%
Madagascar 3573 33 0.92% 2.696931e+07 0.01%
Croatia 3325 114 3.43% 4.076246e+06 0.08%
Thailand 3202 58 1.81% 6.962558e+07 0.00%
Albania 3106 83 2.67% 2.862427e+06 0.11%
Equatorial_Guinea 3071 51 1.66% 1.355982e+06 0.23%
Somalia 3028 92 3.04% 1.544291e+07 0.02%
Nicaragua 2846 91 3.20% 6.545503e+06 0.04%
Paraguay 2554 20 0.78% 7.044639e+06 0.04%
Maldives 2517 13 0.52% 5.309570e+05 0.47%
Cuba 2399 86 3.58% 1.133348e+07 0.02%
Mali 2358 120 5.09% 1.965802e+07 0.01%
South_Sudan 2106 40 1.90% 1.106211e+07 0.02%
Sri_Lanka 2094 11 0.53% 2.132373e+07 0.01%
Estonia 2003 69 3.44% 1.324820e+06 0.15%
Lebanon 1946 36 1.85% 6.855709e+06 0.03%
Malawi 1929 25 1.30% 1.862875e+07 0.01%
Zambia 1895 42 2.22% 1.786103e+07 0.01%
Iceland 1880 10 0.53% 3.569910e+05 0.53%
Lithuania 1854 79 4.26% 2.794184e+06 0.07%
Congo 1821 47 2.58% 5.380504e+06 0.03%
Slovakia 1798 28 1.56% 5.450421e+06 0.03%
Guinea_Bissau 1790 25 1.40% 1.920917e+06 0.09%
Slovenia 1763 111 6.30% 2.080908e+06 0.08%
Sierra_Leone 1584 63 3.98% 7.813207e+06 0.02%
Cape_Verde 1542 18 1.17% 5.499360e+05 0.28%
Yemen 1318 351 26.63% 2.916192e+07 0.00%
Benin 1285 23 1.79% 1.180115e+07 0.01%
Tunisia 1221 50 4.10% 1.169472e+07 0.01%
Rwanda 1194 3 0.25% 1.262694e+07 0.01%
New_Zealand 1190 22 1.85% 4.783062e+06 0.02%
Libya 1182 35 2.96% 6.777453e+06 0.02%
Jordan 1169 10 0.86% 1.010170e+07 0.01%
Latvia 1141 30 2.63% 1.919968e+06 0.06%
Eswatini 1138 14 1.23% 1.148133e+06 0.10%
Niger 1097 68 6.20% 2.331072e+07 0.00%
Mozambique 1071 8 0.75% 3.036604e+07 0.00%
Cyprus 1008 19 1.88% 8.758990e+05 0.12%
Burkina_Faso 1005 53 5.27% 2.032138e+07 0.00%
Uganda 977 0 0.00% 4.426959e+07 0.00%
Uruguay 974 29 2.98% 3.461731e+06 0.03%
Georgia 968 15 1.55% 3.996762e+06 0.02%
Montenegro 960 17 1.77% 6.221820e+05 0.15%
Liberia 926 41 4.43% 4.937374e+06 0.02%
Zimbabwe 885 9 1.02% 1.464547e+07 0.01%
Chad 873 74 8.48% 1.594688e+07 0.01%
Andorra 855 52 6.08% 7.617700e+04 1.12%
Jamaica 751 10 1.33% 2.948277e+06 0.03%
Sao_Tome_and_Principe 724 13 1.80% 2.150480e+05 0.34%
San_Marino 713 42 5.89% 3.445300e+04 2.07%
Cases_on_an_international_conveyance_Japan 696 7 1.01% NaN nan%
Togo 695 15 2.16% 8.082359e+06 0.01%
Malta 673 9 1.34% 4.935590e+05 0.14%
Suriname 665 17 2.56% 5.813630e+05 0.11%
Namibia 593 0 0.00% 2.494524e+06 0.02%
Western_Sahara 519 1 0.19% 5.824580e+05 0.09%
United_Republic_of_Tanzania 509 21 4.13% 5.800546e+07 0.00%
Taiwan 449 7 1.56% 2.377388e+07 0.00%
Angola 386 21 5.44% 3.182530e+07 0.00%
Syria 372 14 3.76% 1.707013e+07 0.00%
Vietnam 369 0 0.00% 9.646211e+07 0.00%
Mauritius 342 10 2.92% 1.269670e+06 0.03%
Isle_of_Man 336 24 7.14% 8.458900e+04 0.40%
Jersey 325 31 9.54% 1.077960e+05 0.30%
Myanmar 318 6 1.89% 5.404542e+07 0.00%
Botswana 314 1 0.32% 2.303703e+06 0.01%
Comoros 313 7 2.24% 8.508910e+05 0.04%
Guam 309 5 1.62% 1.672950e+05 0.18%
Guyana 285 16 5.61% 7.827750e+05 0.04%
Guernsey 252 13 5.16% 6.446800e+04 0.39%
Mongolia 227 0 0.00% 3.225166e+06 0.01%
Eritrea 215 0 0.00% 3.497117e+06 0.01%
Cayman_Islands 201 1 0.50% 6.494800e+04 0.31%
Burundi 191 1 0.52% 1.153058e+07 0.00%
Faroe_Islands 188 0 0.00% 4.867700e+04 0.39%
Gibraltar 179 0 0.00% 3.370600e+04 0.53%
Bermuda 149 9 6.04% 6.250800e+04 0.24%
United_States_Virgin_Islands 144 6 4.17% 1.045790e+05 0.14%
Cambodia 141 0 0.00% 1.648654e+07 0.00%
Brunei_Darussalam 141 3 2.13% 4.332960e+05 0.03%
Trinidad_and_Tobago 133 8 6.02% 1.394969e+06 0.01%
Monaco 108 5 4.63% 3.308500e+04 0.33%
Bahamas 106 11 10.38% 3.894860e+05 0.03%
Aruba 105 3 2.86% 1.063100e+05 0.10%
Barbados 98 7 7.14% 2.870210e+05 0.03%
Seychelles 91 0 0.00% 9.774100e+04 0.09%
Lesotho 91 0 0.00% 2.125267e+06 0.00%
Liechtenstein 85 1 1.18% 3.837800e+04 0.22%
Bhutan 80 0 0.00% 7.630940e+05 0.01%
Sint_Maarten 78 15 19.23% 4.238900e+04 0.18%
Antigua_and_Barbuda 73 3 4.11% 9.711500e+04 0.08%
Gambia 63 3 4.76% 2.347696e+06 0.00%
French_Polynesia 62 0 0.00% 2.792850e+05 0.02%
Turks_and_Caicos_islands 55 2 3.64% 3.819400e+04 0.14%
Northern_Mariana_Islands 31 2 6.45% 5.721300e+04 0.05%
Belize 30 2 6.67% 3.903510e+05 0.01%
Saint_Vincent_and_the_Grenadines 29 0 0.00% 1.105930e+05 0.03%
Curaçao 25 1 4.00% 1.634230e+05 0.02%
Timor_Leste 24 0 0.00% 1.293120e+06 0.00%
Grenada 23 0 0.00% 1.120020e+05 0.02%
Saint_Lucia 22 0 0.00% 1.827950e+05 0.01%
Fiji 21 0 0.00% 8.899550e+05 0.00%
New_Caledonia 21 0 0.00% 2.827570e+05 0.01%
Laos 19 0 0.00% 7.169456e+06 0.00%
Dominica 18 0 0.00% 7.180800e+04 0.03%
Saint_Kitts_and_Nevis 16 0 0.00% 5.283400e+04 0.03%
Falkland_Islands_(Malvinas) 13 0 0.00% 3.372000e+03 0.39%
Greenland 13 0 0.00% 5.666000e+04 0.02%
Holy_See 12 0 0.00% 8.150000e+02 1.47%
Papua_New_Guinea 11 0 0.00% 8.776119e+06 0.00%
Montserrat 11 1 9.09% 4.991000e+03 0.22%
British_Virgin_Islands 8 1 12.50% 3.003300e+04 0.03%
Bonaire, Saint Eustatius and Saba 7 0 0.00% 2.598300e+04 0.03%
Anguilla 3 0 0.00% 1.487200e+04 0.02%

Trends shown for countries with more than 999 reported cases. Double-click on a country name in the legend next to each figure, in order to show only the selected country.

In [35]:
cases_total= cases_total.sort_values("country")
In [36]:
country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "China", "Iran", "France", "United_Kingdom", "Singapore", "Australia", "Ecuador"]
In [37]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [39]:
fig = go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
fig.update_layout(title="Cummulative cases per country")#, yaxis_type="log")
pio.show(fig)
In [41]:
# cases["growfactor"] = cases.newcases / cases.groupby("country")["newcases"].shift(1).fillna(0)

Exponential fitting

In [44]:
cases= cases.loc[cases.cumcases >= 20,:]
In [45]:
cases["datemin"] = cases.groupby("country")["date"].min()
In [46]:
cases["days"]= cases.date - cases.datemin
In [47]:
cases.days= cases.days.dt.days
In [48]:
def exponential_growth(x, a, c_o):
    return c_o*a**x
In [49]:
def country_fit(df, country):
    x= df.loc[country].days
    y= df.loc[country].cumcases
    popt, pcov= curve_fit(exponential_growth, x, y)
    return popt
In [50]:
# country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "Singapore"]
In [51]:
popt_list= []
popt_df= pd.DataFrame(columns= ["A"])
In [52]:
for i, country in enumerate(country_list):
    popt_list.append(country_fit(cases, country))
    popt_df.loc[country]= popt_list[i][0]

Factor A of exponential growth (C = Co * A^d)

It can be interpreted as an average daily increase factor of total cases.

In [53]:
popt_df.sort_values("A", ascending= False)
Out[53]:
A
Palestine 1.080212
Malawi 1.057288
Iraq 1.055713
Nepal 1.054762
Mauritania 1.053958
South_Africa 1.052129
Libya 1.049275
Kazakhstan 1.048620
Honduras 1.046291
Guatemala 1.045650
Venezuela 1.044485
Kyrgyzstan 1.044466
Ethiopia 1.044366
Argentina 1.044196
Madagascar 1.042661
Bolivia 1.042349
Benin 1.042278
Colombia 1.041536
Kenya 1.041395
Oman 1.041137
India 1.039839
Central_African_Republic 1.039810
Costa_Rica 1.038478
Bangladesh 1.038174
Yemen 1.037800
Azerbaijan 1.037338
Haiti 1.037313
El_Salvador 1.037057
Mozambique 1.036912
Brazil 1.036803
Cote_dIvoire 1.035673
Chile 1.035403
Nicaragua 1.035250
Eswatini 1.035233
Armenia 1.034920
Egypt 1.034906
Pakistan 1.034530
Nigeria 1.034145
Mexico 1.034101
Cape_Verde 1.033665
Democratic_Republic_of_the_Congo 1.031528
Equatorial_Guinea 1.031215
Bahrain 1.031043
Gabon 1.030819
Afghanistan 1.030716
Saudi_Arabia 1.030633
Ghana 1.030584
Congo 1.029711
Panama 1.029697
South_Sudan 1.029390
Sudan 1.029130
Cameroon 1.028545
Kuwait 1.028312
Indonesia 1.028311
North_Macedonia 1.028164
Paraguay 1.028118
Uzbekistan 1.028081
Rwanda 1.028017
Kosovo 1.027693
Peru 1.027383
Senegal 1.027080
Philippines 1.026832
Qatar 1.026448
Sierra_Leone 1.025645
Dominican_Republic 1.025499
Zambia 1.025460
Moldova 1.025382
Russia 1.024741
Ukraine 1.024710
Puerto_Rico 1.024644
Tajikistan 1.024216
Albania 1.023761
Mali 1.023471
Bulgaria 1.023063
Belarus 1.022706
Djibouti 1.022411
United_Arab_Emirates 1.022121
Sweden 1.021894
Maldives 1.021656
Algeria 1.021502
Somalia 1.021079
Guinea_Bissau 1.020871
Guinea 1.020723
Singapore 1.020162
Sri_Lanka 1.019953
Morocco 1.019907
Bosnia_and_Herzegovina 1.019340
United_States_of_America 1.019325
Ecuador 1.019148
Poland 1.018925
Iran 1.017313
Romania 1.017128
Canada 1.016253
Lebanon 1.015623
United_Kingdom 1.015207
Jordan 1.015202
Serbia 1.014918
Japan 1.014491
Turkey 1.014169
Portugal 1.014142
Israel 1.013783
Cuba 1.013048
Malaysia 1.012864
Hungary 1.012764
Finland 1.012216
Czechia 1.012115
Ireland 1.011979
Denmark 1.011824
Netherlands 1.011683
France 1.011547
Belgium 1.011195
Germany 1.011051
Burkina_Faso 1.010734
Italy 1.010492
Slovakia 1.010463
Thailand 1.010345
Croatia 1.010258
Greece 1.010255
Spain 1.010182
Australia 1.009896
Latvia 1.009514
Niger 1.009512
Lithuania 1.009275
Cyprus 1.009057
Norway 1.008949
Tunisia 1.008912
Switzerland 1.008847
Austria 1.008735
Estonia 1.008622
Slovenia 1.007542
Luxembourg 1.007447
South_Korea 1.007412
Iceland 1.007196
New_Zealand 1.005677
China 1.005471

Exponential fitting

In [54]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].days, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
    fig.add_trace(go.Scatter(x= cases.loc[country].days,
                             y= exponential_growth(cases.loc[country].days, *popt_list[i]),
                             mode= "lines",
                             name= "exponential fit"))
fig.update_layout(title= "Exponential fit per country")

pio.show(fig)

Change in the number of reported new cases

A positive change means an increase in the number of reported cases. A negative change means a decrease in the number of new cases, that means good news!

In [55]:
country_list= ["Italy", "Germany", "Spain", "South_Korea", "United_States_of_America", "China", "Iran", "France", "United_Kingdom", "Singapore", "Australia", "Ecuador"]
In [56]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [57]:
cases["growspeed"]= cases.newcases - cases.groupby("country").newcases.shift(1).fillna(0)
In [58]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Daily change in number of new cases")

pio.show(fig)
In [59]:
#### Grow speed with different aggregations
In [60]:
cases= cases.reset_index()
In [61]:
cases= cases.set_index("date")
In [62]:
cases_2d= cases.groupby("country").resample(pd.Timedelta(days= 2)).sum().loc[:,["newcases"]]
In [63]:
cases_3d= cases.groupby("country").resample(pd.Timedelta(days= 3)).sum().loc[:,["newcases"]]
In [64]:
cases_4d= cases.groupby("country").resample(pd.Timedelta(days= 4)).sum().loc[:,["newcases"]]
In [65]:
cases_7d= cases.groupby("country").resample(pd.Timedelta(days= 7)).sum().loc[:,["newcases"]]
In [66]:
# Grow speed
In [67]:
cases_2d["growspeed"]= cases_2d.newcases - cases_2d.groupby("country").newcases.shift(1).fillna(0)
In [68]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_2d.loc[country].index, 
                             y= cases_2d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (2 days period)")
pio.show(fig)
In [69]:
cases_3d["growspeed"]= cases_3d.newcases - cases_3d.groupby("country").newcases.shift(1).fillna(0)
In [70]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_3d.loc[country].index, 
                             y= cases_3d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (3 days period)")

pio.show(fig)
In [71]:
cases_4d["growspeed"]= cases_4d.newcases - cases_4d.groupby("country").newcases.shift(1).fillna(0)
In [72]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_4d.loc[country].index, 
                             y= cases_4d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (4 days period)")
pio.show(fig)
In [73]:
cases_7d["growspeed"]= cases_7d.newcases - cases_7d.groupby("country").newcases.shift(1).fillna(0)
In [74]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_7d.loc[country].index, 
                             y= cases_7d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (1 week period)")
pio.show(fig)
In [75]:
cases= cases.reset_index()
In [76]:
cases= cases.set_index("country")
In [77]:
#!jupyter nbconvert --to html --template toc2 EAP.ipynb